<?php

class Damages_Methods_Request_Edit_EmailTemplate extends Damages_Methods_Request {

  /**
   *
   * @var Damages_Methods_Data_Email_Edit 
   */
  public $template;

  public function __construct($params) {
    $this->template = new Damages_Methods_Data_Email_Edit($params->template);
    parent::__construct($params);
  }

  /**
   * 
   * @return Damages_Methods_Response
   */
  public function process() {
    if (!Damages_Auth::getInstance()->checkPermission(Damages_Auth::PERMISSION_ADMIN))
      throw new Damages_Exception_App(Damages_Codes::ACCESS_DENIED);
    $obj = DamagesEmailTemplatesQuery::create()->findOneById($this->template->id);
    if (!$obj instanceof DamagesEmailTemplates)
      throw new Damages_Exception_App(Damages_Codes::DB_OBJECT_NOT_FOUND, array($this->template->id));
    if (!$this->validateTemplate())
      throw new Damages_Exception_App(Damages_Codes::EMAIL_TEMPLATE_ERRORS);
    $obj->setTemplate($this->template->template);
    $obj->save();
    $response = new Damages_Methods_Response(true);
    return $response;
  }

  private function validateTemplate() {
    return true;
  }

}